{% extends "page_base.html" %}

{% load static %}
{% load i18n %}
{% load inventree_extras %}

{% block page_title %}
{% inventree_title %} | {% trans "Supplier List" %}
{% endblock %}

{% block heading %}
{{ title }}
{% endblock %}

{% block actions %}
{% if pagetype == 'manufacturers' and roles.purchase_order.add or pagetype == 'suppliers' and roles.purchase_order.add or pagetype == 'customers' and roles.sales_order.add %}
<button type='button' class="btn btn-success" id='new-company'>
    <span class='fas fa-plus-circle'></span> {{ button_text }}
</button>
{% endif %}
{% endblock %}

{% block page_info %}

<div class='panel-content'>

    <div id='button-toolbar'>
        {% include "filter_list.html" with id='company' %}
    </div>

    <table class='table table-striped table-condensed' id='company-table' data-toolbar='#button-toolbar'>
    </table>
</div>

{% endblock %}
{% block js_ready %}
{{ block.super }}

    $('#new-company').click(function() {

        var fields = companyFormFields();

        // Field overrides
        fields.is_supplier.value = {% if pagetype == 'suppliers' %}true{% else %}false{% endif %};
        fields.is_manufacturer.value = {% if pagetype == 'manufacturers' %}true{% else %}false{% endif %};
        fields.is_customer.value = {% if pagetype == 'customers' %}true{% else %}false{% endif %};

        createCompany({
            fields: fields,
        });
    });

    loadCompanyTable("#company-table", "{% url 'api-company-list' %}",
        {
            pagetype: '{{ pagetype }}',
            params: {
                {% for key,value in filters.items %}{{ key }}: "{{ value }}",{% endfor %}
            }
        }
    );

{% endblock %}
